﻿using System;
using System.Collections.Generic;

namespace Framework.Data
{
    public interface IRepository
    {
        void Add<T>(T entity) where T : class; 
        int AddThenSaveChange<T>(T entity) where T : class;
        void Attach<T>(T entity, Action<T> action = null) where T : class;
        int AttachThenSaveChange<T>(T entity, Action<T> action = null) where T : class;
        int Count<T>() where T : class;
        int Count<T>(System.Linq.Expressions.Expression<Func<T, bool>> where) where T : class;
        System.Data.Entity.DbContext DbContext { get; }
        void Delete<T>(T entity) where T : class;
        int DeleteThenSaveChange<T>(T entity) where T : class;
        int ExecuteCommand(string sql, params object[] parameters);
        T First<T, TKey>(System.Linq.Expressions.Expression<Func<T, bool>> where, System.Linq.Expressions.Expression<Func<T, object>> select, System.Linq.Expressions.Expression<Func<T, TKey>> orderBy, bool desc = false) where T : class;
        T First<T, TKey>(System.Linq.Expressions.Expression<Func<T, bool>> where, System.Linq.Expressions.Expression<Func<T, TKey>> orderBy, bool desc = false) where T : class;
        T First<T, TKey>(System.Linq.Expressions.Expression<Func<T, object>> select, System.Linq.Expressions.Expression<Func<T, TKey>> orderBy, bool desc = false) where T : class;
        T First<T, TKey>(System.Linq.Expressions.Expression<Func<T, TKey>> orderBy, bool desc = false) where T : class;
        T First<T>() where T : class;
        T First<T>(System.Linq.Expressions.Expression<Func<T, bool>> where) where T : class;
        T First<T>(System.Linq.Expressions.Expression<Func<T, bool>> where, System.Linq.Expressions.Expression<Func<T, object>> select) where T : class;
        T First<T>(System.Linq.Expressions.Expression<Func<T, object>> select) where T : class;
        bool FirstBoolean<T, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, bool>> select, System.Linq.Expressions.Expression<Func<T, bool>> where, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        bool FirstBoolean<T, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, bool>> select, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        bool? FirstBoolean<T, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, bool?>> select, System.Linq.Expressions.Expression<Func<T, bool>> where, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        bool? FirstBoolean<T, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, bool?>> select, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        bool FirstBoolean<T>(Func<T, bool> select) where T : class;
        bool? FirstBoolean<T>(Func<T, bool?> select) where T : class;
        bool FirstBoolean<T>(System.Linq.Expressions.Expression<Func<T, bool>> select, System.Linq.Expressions.Expression<Func<T, bool>> where) where T : class;
        bool? FirstBoolean<T>(System.Linq.Expressions.Expression<Func<T, bool?>> select, System.Linq.Expressions.Expression<Func<T, bool>> where) where T : class;
        decimal FirstDecimal<T, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, decimal>> select, System.Linq.Expressions.Expression<Func<T, bool>> where, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        decimal FirstDecimal<T, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, decimal>> select, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        decimal? FirstDecimal<T, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, decimal?>> select, System.Linq.Expressions.Expression<Func<T, bool>> where, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        decimal? FirstDecimal<T, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, decimal?>> select, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        decimal FirstDecimal<T>(Func<T, decimal> select) where T : class;
        decimal? FirstDecimal<T>(Func<T, decimal?> select) where T : class;
        decimal FirstDecimal<T>(System.Linq.Expressions.Expression<Func<T, decimal>> select, System.Linq.Expressions.Expression<Func<T, bool>> where) where T : class;
        decimal? FirstDecimal<T>(System.Linq.Expressions.Expression<Func<T, decimal?>> select, System.Linq.Expressions.Expression<Func<T, bool>> where) where T : class;
        double FirstDouble<T, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, double>> select, System.Linq.Expressions.Expression<Func<T, bool>> where, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        double FirstDouble<T, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, double>> select, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        double? FirstDouble<T, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, double?>> select, System.Linq.Expressions.Expression<Func<T, bool>> where, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        double? FirstDouble<T, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, double?>> select, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        double FirstDouble<T>(Func<T, double> select) where T : class;
        double? FirstDouble<T>(Func<T, double?> select) where T : class;
        double FirstDouble<T>(System.Linq.Expressions.Expression<Func<T, double>> select, System.Linq.Expressions.Expression<Func<T, bool>> where) where T : class;
        double? FirstDouble<T>(System.Linq.Expressions.Expression<Func<T, double?>> select, System.Linq.Expressions.Expression<Func<T, bool>> where) where T : class;
        int FirstInt<T, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, int>> select, System.Linq.Expressions.Expression<Func<T, bool>> where, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        int FirstInt<T, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, int>> select, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        int? FirstInt<T, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, int?>> select, System.Linq.Expressions.Expression<Func<T, bool>> where, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        int? FirstInt<T, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, int?>> select, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        int FirstInt<T>(Func<T, int> select) where T : class;
        int? FirstInt<T>(Func<T, int?> select) where T : class;
        int FirstInt<T>(System.Linq.Expressions.Expression<Func<T, int>> select, System.Linq.Expressions.Expression<Func<T, bool>> where) where T : class;
        int? FirstInt<T>(System.Linq.Expressions.Expression<Func<T, int?>> select, System.Linq.Expressions.Expression<Func<T, bool>> where) where T : class;
        TResult FirstPrimitives<T, TResult, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, TResult>> select, System.Linq.Expressions.Expression<Func<T, bool>> where, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        TResult FirstPrimitives<T, TResult, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, TResult>> select, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        TResult FirstPrimitives<T, TResult>(Func<T, TResult> select) where T : class;
        TResult FirstPrimitives<T, TResult>(System.Linq.Expressions.Expression<Func<T, TResult>> select, System.Linq.Expressions.Expression<Func<T, bool>> where) where T : class;
        string FirstString<T, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, string>> select, System.Linq.Expressions.Expression<Func<T, bool>> where, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        string FirstString<T, TOrderByProperty>(System.Linq.Expressions.Expression<Func<T, string>> select, System.Linq.Expressions.Expression<Func<T, TOrderByProperty>> orderBy, bool desc = false) where T : class;
        string FirstString<T>(Func<T, string> select) where T : class;
        string FirstString<T>(System.Linq.Expressions.Expression<Func<T, string>> select, System.Linq.Expressions.Expression<Func<T, bool>> where) where T : class;
        IList<T> Get<T>() where T : class;
        IList<T> Get<T>(System.Linq.Expressions.Expression<Func<T, bool>> where) where T : class;
        IList<T> Get<T>(System.Linq.Expressions.Expression<Func<T, bool>> where, System.Linq.Expressions.Expression<Func<T, object>> select) where T : class;
        IList<T> Get<T>(System.Linq.Expressions.Expression<Func<T, object>> select) where T : class;
        IList<T> Get<T>(string sql, params object[] parameters);
        T GetByKey<T>(params object[] keyValues) where T : class;
        IList<T> GetPaged<T, TKey>(int pageIndex, int pageSize, out int recordCount, System.Linq.Expressions.Expression<Func<T, bool>> where, System.Linq.Expressions.Expression<Func<T, TKey>> orderBy, bool desc = false) where T : class;
        IList<T> GetPaged<T, TKey>(int pageIndex, int pageSize, out int recordCount, System.Linq.Expressions.Expression<Func<T, object>> select, System.Linq.Expressions.Expression<Func<T, bool>> where, System.Linq.Expressions.Expression<Func<T, TKey>> orderBy, bool desc = false) where T : class;
        IList<T> GetPaged<T, TKey>(int pageIndex, int pageSize, out int recordCount, System.Linq.Expressions.Expression<Func<T, object>> select, System.Linq.Expressions.Expression<Func<T, TKey>> orderBy, bool desc = false) where T : class;
        IList<T> GetPaged<T, TKey>(int pageIndex, int pageSize, out int recordCount, System.Linq.Expressions.Expression<Func<T, TKey>> orderBy, bool desc = false) where T : class;
        System.Linq.IQueryable<T> GetQuery<T>(System.Linq.Expressions.Expression<Func<T, bool>> where = null) where T : class;
        int Save();
        void TransactionCommit();
        IUnitOfWork TransactionStart();
    }
}
